package com.neusoft.zygh.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.neusoft.zygh.utils.FileUpload;


@RestController
@RequestMapping("/image")
public class ImageController {
	// 读取配置文件
	@Value("${uploadPath}")
	private String uploadPath;

	/**
	 * 上传
	 */
	@RequestMapping(value="/upload",method=RequestMethod.POST)
	public Map<String, Object> uploadPicture(@RequestParam("file") MultipartFile file) {
		Map<String, Object> map=new HashMap<>();
		String filename = FileUpload.uplaod(uploadPath, file);
		if(filename!=null){
			map.put("data", "/pic/"+filename);
			map.put("code", 200);
		}
		return map;
	}
}
